﻿// Picturez
//
// Copyright © Frank Nagl, 2008-2012
// admin@franknagl.de
// www.franknagl.de
//
namespace Picturez
{
    using System;
    using System.Drawing.Imaging;
    using System.Windows.Forms;

    partial class ImageCutForm
    {
        private void ItemCloseClick(object sender, EventArgs e)
        {
            Close();
        }

        private void ItemInfoClick(object sender, EventArgs e)
        {
            Program.ShowInfoForm(Icon);
        }

        private void ItemLanguageClick(object sender, EventArgs e)
        {
            if (language.Text == LanguagesImageCut.German)
            {
                IOFile.WriteLine(Program.OptionsFile, 5, "Language;English", true);
                language.Text = LanguagesImageCut.English;
                SetStrings();
            }
            else  //if (mLanguage.Text == Languages.English)
            {
                IOFile.WriteLine(Program.OptionsFile, 5, "Language;German", true);
                language.Text = LanguagesImageCut.German;
                SetStrings();
            }
        }

        private void ItemUseFastCutClick(object sender, EventArgs e)
        {
            //Reset ratio constraints
            mComboBox_ratio.SelectedIndex = 0;
            if (Current.Name == "")
            {
                MessageBoxOk.Show(language.Text[44], language.Text[43]);
                return;
            }

            LoadFastcut(Current.Name);
        }

        private void LoadFastcutItemsClick(object sender, EventArgs e)
        {
            ToolStripMenuItem item = sender as ToolStripMenuItem;
            if (item != null)
            {
                LoadFastcut(item.Text);
            }
        }

        private void RemoveFastcutItemsClick(object sender, EventArgs e)
        {
            if (MessageBoxOkCancel.Show(
                language.Text[27], language.Text[30]) == DialogResult.Cancel)
            {
                return;
            }

            ToolStripMenuItem item = sender as ToolStripMenuItem;
            if (item != null)
            {
                // string name = item.Text;
                fastcuts.Remove(item.Text);
                Program.SaveXml(fastcuts);
                UpdateFastcutToolStripMenuItems();
            }
        }

        private void SaveFastcutToolStripMenuItemClick(object sender, EventArgs e)
        {
            if (StringDialog.Show(
                    ref tmpFastcutName,
                    language.Text[13],
                    language.Text[14],
                    tmpFastcutName, // Current.Name,
                    "OK",
                    language.Text[15]) == DialogResult.Cancel)
            {
                return;
            }

            if (fastcuts.Exists(tmpFastcutName))
            {
                if (MessageBoxOkCancel.Show(
                        language.Text[19],
                        language.Text[18]) == DialogResult.Cancel)
                {
                    SaveFastcutToolStripMenuItem.PerformClick();
                    return;
                }
                fastcuts.Remove(Current);
                // resetting name, because after removing Current.Name = ""
                Current.Name = tmpFastcutName;
            }
            else
            {
                Current.Name = tmpFastcutName;
            }

            fastcuts.AddAsFirst(Current.Clone() as Fastcut);
            Program.SaveXml(fastcuts);
            UpdateFastcutToolStripMenuItems();
        }

        private void SaveToolStripMenuItemClick(object sender, EventArgs e)
        {
            image.Save(path, image.RawFormat);
            isImageEdited = false;
            Text = Text.Replace("*", "");
        }

        private void SaveAsToolStripMenuItemClick(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            //tDialog.InitialDirectory = "c:\\";
            dialog.Filter =
            "PNG (*.png)|*.png|JPEG Files(*.jpg;*.jpeg)|*.jpg;*.jpeg|" + 
            "BMP (*.bmp)|*.bmp|TIFF Files(*.tif;*.tiff)|*.tif;*.tiff|" + 
            "GIF (*.gif)|*.gif|EMF (*.emf)|*.emf|WMF (*.wmf)|*.wmf";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                switch (dialog.FilterIndex)
                {
                    case 1: image.Save(dialog.FileName, ImageFormat.Png); break;
                    case 2:
                        if (image.RawFormat.Equals(ImageFormat.Jpeg))
                        {
                            image.Save(dialog.FileName, ImageFormat.Jpeg);
                        }
                        else
                        {
                            //100% quality
                            JpegEncoder.SaveJpeg(dialog.FileName, image, 100);
                        }
                        break;
                    case 3: image.Save(dialog.FileName, ImageFormat.Bmp); break;
                    case 4: image.Save(dialog.FileName, ImageFormat.Tiff); break;
                    case 5: image.Save(dialog.FileName, ImageFormat.Gif); break;
                    case 6: image.Save(dialog.FileName, ImageFormat.Emf); break;
                    case 7: image.Save(dialog.FileName, ImageFormat.Wmf); break;
                }
            }
        }
    }
}
